<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once('app/libraries/excel/PHPExcel.php');
$page_title = "Danh sách Webmaster subcribe";
		// Create new PHPExcel object
    	$objPHPExcel = new PHPExcel();
    	// Set properties
    	$objPHPExcel->getProperties()->setCreator("AdMarket")
    								 ->setLastModifiedBy("AdMarket")
    								 ->setTitle("Office 2007 XLSX Document")
    								 ->setSubject("Office 2007 XLSX Document")
    								 ->setDescription($page_title)
    								 ->setCategory("");
	
	   $styleArray = array(
			'font' => array(
				'bold' => true,
			),
			'alignment' => array(
				'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
			),
			'borders' => array(
				'top' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN,
				),
			)
		);
		
		$objPHPExcel->getActiveSheet()->mergeCells('A1:F1');
		
    	$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $page_title);
    	$objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray);
    	$objPHPExcel->getActiveSheet()->getStyle('A3')->applyFromArray($styleArray);
    	$objPHPExcel->getActiveSheet()->getStyle('B3')->applyFromArray($styleArray);
    	$objPHPExcel->getActiveSheet()->getStyle('C3')->applyFromArray($styleArray);
    	$objPHPExcel->getActiveSheet()->getStyle('D3')->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyle('E3')->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyle('F3')->applyFromArray($styleArray);
		
    	$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
    	$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
    	$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
        
		$objPHPExcel->setActiveSheetIndex(0)
    				->setCellValue('A3', '#')
    	            ->setCellValue('B3', 'Website')
    	            ->setCellValue('C3', 'Website Admin')
    	            ->setCellValue('D3', 'Email')
    	            ->setCellValue('E3', 'Phone')
    	            ->setCellValue('F3', 'Created time')
    				;
		
		$index = 4;
        foreach($list as $item)
        {
        	$objPHPExcel->setActiveSheetIndex(0)
    					->setCellValue('A'.$index, $index-1)
            			->setCellValue('B'.$index, $item['site_url'])
            			->setCellValue('C'.$index, $item['site_admin'])
            			->setCellValue('D'.$index, $item['email'])
            			->setCellValue('E'.$index, ' '.$item['phone'])
    					->setCellValue('F'.$index, $item['create_time']);
    		$index++;
        }
        
        header('Content-Type: application/vnd.ms-excel');
       	header('Content-Disposition: attachment;filename="AdMarket_Webmaster_Subcribe.xls"');
        header('Cache-Control: max-age=0');
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');   
    	$objWriter->save('php://output');
    	exit;